<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">



	<ui:define name="corpoForm">
		


		<h:form id="formBotoesMeta" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarMeta" value="#{rsc.label_criar}"
					rendered="#{p:ifGranted('CRIAR_META')}" styleClass="botao"
					action="#{manterMetaBean.criarEntidade}" ajax="false"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterMetaBean.preRenderList}" />
		<h:form id="formListComissoes" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">
				<p:panelGrid columns="5">

					<p:outputLabel value="#{rsc.label_nome}" for="acMeta" />

					<p:outputLabel value="#{rsc.label_periodoMeta}" for="cldDataInicio" />

					<p:outputLabel value="#{rsc.label_filial}" for="cmbFilial" />

					<p:outputLabel value="#{rsc.label_ativo}" for="cmbAtivo" />

					<p:spacer />

					<p:autoComplete id="acMeta" minQueryLength="3" size="20"
						value="#{manterMetaBean.filtro.nome}" effect="fade" maxResults="7"
						completeMethod="#{manterMetaBean.autoCompleteNome}">
						<p:ajax event="change"
							listener="#{manterMetaBean.buscarPorFiltros}"
							update="listaComissoes" />
					</p:autoComplete>

					<p:column>
						<p:calendar pattern="dd/MM/yyyy" size="8" showOn="button"
							id="cldDataInicio" value="#{manterMetaBean.filtro.dataInicio}">
							<p:ajax event="change"
								listener="#{manterMetaBean.buscarPorFiltros}"
								update="listaComissoes" />
						</p:calendar>

						<p:calendar pattern="dd/MM/yyyy" size="8" showOn="button"
							id="cldDataFim" value="#{manterMetaBean.filtro.dataFim}">
							<p:ajax event="change"
								listener="#{manterMetaBean.buscarPorFiltros}"
								update="listaComissoes" />
						</p:calendar>
					</p:column>

					<p:selectOneMenu style="width: 100px" label="#{rsc.label_filial}"
						value="#{manterMetaBean.filtro.idFilial}" id="cmbFilial">
						<f:selectItems value="#{manterMetaBean.formulario.filiais}"
							var="c" itemLabel="#{c.nome}" itemValue="#{c.id}" />
					</p:selectOneMenu>

					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterMetaBean.filtro.ativo}" id="cmbAtivo">
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterMetaBean.status}" var="c"
							itemLabel="#{c.label}" itemValue="#{c}" />
						<p:ajax event="change"
							listener="#{manterMetaBean.buscarPorFiltros}"
							update="listaComissoes" />
					</p:selectOneMenu>

					<p:commandButton update="listaComissoes"
						actionListener="#{manterMetaBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>

			<p:panel id="pnlListaComissoes"
				header="#{rsc.label_metasCadastradas}" toggleable="true"
				toggleSpeed="500">

				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="meta" id="listaComissoes" sortMode="multiple"
						widgetVar="listaComissoesWid" value="#{manterMetaBean.entidades}"
						paginator="true" rows="10"
						paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">

						<p:column headerText="#{rsc.label_codigo}" sortBy="#{meta.id}">
							<h:outputText value="#{meta.id}" />
						</p:column>

						<p:column headerText="#{rsc.label_nome}" sortBy="#{meta.nome}">
							<h:outputText value="#{meta.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_dataInicio}"
							sortBy="#{meta.dataInicio}">
							<h:outputText value="#{meta.dataInicio}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p:column>

						<p:column headerText="#{rsc.label_dataFim}"
							sortBy="#{meta.dataFim}">
							<h:outputText value="#{meta.dataFim}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p:column>

						<p:column headerText="#{rsc.label_filial}"
							sortBy="#{meta.filial.nome}">
							<h:outputText value="#{meta.filial.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_ativo}" sortBy="#{meta.ativo}"
							styleClass="centralizado">
							<p:outputLabel value="#{rsc.label_sim}" rendered="#{meta.ativo}" />
							<p:outputLabel value="#{rsc.label_nao}" rendered="#{!meta.ativo}" />
						</p:column>


						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">

							<p:commandButton update=":habilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_META') and !meta.ativo}"
								oncomplete="habilitar.show()" icon="ui-icon ui-icon-locked"
								title="#{rsc.label_habilitar}">
								<f:setPropertyActionListener value="#{meta}"
									target="#{manterMetaBean.entidade}" />
							</p:commandButton>

							<p:commandButton update=":desabilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_META') and meta.ativo}"
								oncomplete="desabilitar.show()" icon="ui-icon ui-icon-unlocked"
								title="#{rsc.label_desabilitar}">
								<f:setPropertyActionListener value="#{meta}"
									target="#{manterMetaBean.entidade}" />
							</p:commandButton>

							<p:commandButton icon="ui-icon ui-icon-pencil"
								rendered="#{p:ifGranted('ALTERAR_META')}"
								title="#{rsc.label_editar}" ajax="false" action="editarMeta">
								<f:setPropertyActionListener value="#{meta}"
									target="#{manterMetaBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>

			<p:watermark value="#{rsc.wm_nomeMetaConsulta}" for="acMeta"></p:watermark>
			<p:watermark value="#{rsc.wm_data}" for="cldDataInicio"></p:watermark>
			<p:watermark value="#{rsc.wm_data}" for="cldDataFim"></p:watermark>
		</h:form>


		<p:confirmDialog message="#{msg.questionConfirmaHabilitar}"
			appendTo="@(body)" width="250" id="habilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="habilitar">
			<h:form id="habilitarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterMetaBean.habilitar}"
					oncomplete="habilitar.hide()" styleClass="botao"
					update=":formListComissoes:listaComissoes, :growl" />
				<p:commandButton value="#{rsc.label_nao}" onclick="habilitar.hide()"
					styleClass="botao" />
			</h:form>
		</p:confirmDialog>

		<p:confirmDialog message="#{msg.questionConfirmaDesabilitar}"
			appendTo="@(body)" width="250" id="desabilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="desabilitar">
			<h:form id="desabilitarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterMetaBean.desabilitar}"
					oncomplete="desabilitar.hide()" styleClass="botao"
					update=":formListComissoes:listaComissoes, :growl" />
				<p:commandButton value="#{rsc.label_nao}" styleClass="botao"
					onclick="desabilitar.hide()" type="button" />
			</h:form>
		</p:confirmDialog>

	</ui:define>
</ui:composition>

